package edu.chalmers.platypus.view.gui;

import java.awt.Dimension;

import javax.swing.ImageIcon;

/**
 * Panel which shows a preview image.
 */
public class ImagePreviewPanel extends javax.swing.JPanel {

    /** Constructor */
    public ImagePreviewPanel() {
	initComponents();
    }

    /**
     * Sets preview image.
     * 
     * @param img
     *            image that will be shown as preview
     */
    public void setImage(ImageIcon img) {
	image = img;
	updateImage();
    }

    /** Grays out the preview image */
    public void engageWaitState() {
	previewLabel.setEnabled(false);
    }

    /** Updates set image */
    private void updateImage() {
	// Sets minimum size so panel is resizable downwards
	previewLabel.setMinimumSize(new Dimension(0, 0));
	this.setMinimumSize(new Dimension(0, 0));

	previewLabel.setEnabled(true);
	previewLabel.setIcon(image);
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed"
    // desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

	previewLabel = new javax.swing.JLabel();

	setName("Form"); // NOI18N

	previewLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
	previewLabel.setName("previewLabel"); // NOI18N
	previewLabel.setOpaque(true);

	javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
	this.setLayout(layout);
	layout.setHorizontalGroup(layout.createParallelGroup(
		javax.swing.GroupLayout.Alignment.LEADING).addComponent(
		previewLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 175,
		Short.MAX_VALUE));
	layout.setVerticalGroup(layout.createParallelGroup(
		javax.swing.GroupLayout.Alignment.LEADING).addComponent(
		previewLabel, javax.swing.GroupLayout.DEFAULT_SIZE, 130,
		Short.MAX_VALUE));
    }// </editor-fold>//GEN-END:initComponents

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel previewLabel;
    // End of variables declaration//GEN-END:variables

    /** Reference to current preview image */
    private ImageIcon image;
}
